﻿using Application.AppService.IConfig;
using Application.AppService.IConfig.Dto.Config_file_first_kind;
using AutoMapper;
using Domain.Entity.Config;
using Microsoft.AspNetCore.Mvc;

namespace UI.Controllers
{
    public class CFFKController : Controller
    {
        private readonly IConfig_file_first_kindAppService cFFKAppService;
        private readonly IMapper mapper;

        public CFFKController(IConfig_file_first_kindAppService cFFKAppService, IMapper mapper)
        {
            this.cFFKAppService = cFFKAppService;
            this.mapper = mapper;
        }
        public IActionResult Index()
        {
            return View();
        }
        public async Task<IActionResult> AddCFFK(Config_file_first_kindUpdateDto updateDto)
        {
            Config_file_first_kind cFFK = mapper.Map<Config_file_first_kind>(updateDto);
            int i = await cFFKAppService.AddCFFKAsync(cFFK);
            return Json(i);
        }
        public async Task<IActionResult> UpdateCFFK(Config_file_first_kindAddDto addDto)
        {
            Config_file_first_kind cFFK = mapper.Map<Config_file_first_kind>(addDto);
            int i = await cFFKAppService.UpdateCFFKAsync(cFFK);
            return Json(i);
        }

        [HttpPost("GetCFFK")]
        public async Task<IActionResult> GetCFFK()
        {
            List<Config_file_first_kind> cFFK=await cFFKAppService.SelectCFFK();
            return Json(cFFK);
        }
        public async Task<IActionResult> DeleteCFFK(int id)
        {
            int i = await cFFKAppService.DeleteCFFKAsync(id);
            return Json(i);
        }
    }
}
